//
//  FmdbUtil.m
//  Rong360
//
//  Created by tianliwei on 9/2/14.
//  Copyright (c) 2014 tianliwei. All rights reserved.
//

#import "FmdbUtil.h"

@implementation FmdbUtil

- (id)initWithDatabase{
    self = [super init];
    if (self) {
        //        NSString *path = [[NSBundle mainBundle]pathForResource:DBFILEINBUNDLE ofType:@"db"];
        NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentDir = [pathArray objectAtIndex:0];
        NSString *path = [documentDir stringByAppendingPathComponent:@"rong360.db"];
        NSLog(@"database Path : %@",path);
        self.db = [[FMDatabase alloc]initWithPath:path];
    }
    return self;
}

- (BOOL)createTableIfNotExist{
    if (![self.db open]) {
        NSLog(@"Could not open db.");
    }
    BOOL success = [self.db executeUpdate:@"CREATE TABLE IF NOT EXISTS messageinfo(id INTEGER PRIMARY KEY AUTOINCREMENT,title,description,url)"];
    return success;
}
- (BOOL)closeDatabase{
    if ([self.db open]) {
        [self.db close];
        return YES;
    }
    return NO;
}
@end
